
%MACRO compute_anyuse (in,out);

*****************************************************************************
* Program: COMPUTE_ANYUSE					   						
* 																			
* Description: Computes any use outcome variable and associated time.
*						
* Last modified: July 27, 2015												
* Created by: Martin Wegman													
*****************************************************************************;

%let dat = data;

data loc.&dat.1;
	set loc.&in;
run;

****************************************************************************;
****************************************************************************;
**************      Compute any drug use         ***************************;
****************************************************************************;
****************************************************************************;

%MACRO CREATE_ANY;

	data loc.&out;
		set loc.&dat.1;
	run;

	%let pts = 9;
	%let months = 0 1 2 3 4 6 9 12 15; 

	%do i = 1 %to &pts;

		%let j = %scan(&months,&i," ");

		data loc.&out;
			set loc.&out;

			temp = Y&j._opi + Y&j._amp + Y&j._bzd;
			
			if temp = . then Y&j._any = .;
			else if temp > 0.1 then Y&j._any = 1;
			else Y&j._any = 0;

			Y&j._cnt = temp;

			drop temp;

		run;

	%end;

%MEND CREATE_ANY;

%CREATE_ANY;

/*
*Examine result;

proc sort data = loc.&dat.&out; by site; run;

proc freq data = loc.&dat.&out;
	by site;
	where urines_observed and imp in('c1','p1');
	tables Y0_any Y1_any Y2_any Y3_any Y4_any Y6_any Y9_any Y12_any Y15_any;
run;

proc freq data = loc.&dat.&out;
	by site;
	where urines_observed and imp in('c1','p1');
	tables Y0_opi Y1_opi Y2_opi Y3_opi Y4_opi Y6_opi Y9_opi Y12_opi Y15_opi;
run;

proc print data = loc.&out;
	where urines_observed and imp in('c1','p1') and urines_observed > 0 and Y0_any = .;
	var client_id site T0--T15 F0--F15;
run;
*/

****************************************************************************;
****************************************************************************;
************          Delete working datasets             ******************;
****************************************************************************;
****************************************************************************;

proc datasets lib=loc nolist;       
	delete &dat.1;
	run;
quit;

****************************************************************************;
****************************************************************************;
**************                END                ***************************;
****************************************************************************;
****************************************************************************;

%MEND compute_anyuse;
